<template>
  <div>
    <script id="editor" type="text/plain" ></script>
  </div>
</template>

<script>
  /* eslint-disable */
  import '../../../../static/ueditor/ueditor.config.js'
  import '../../../../static/ueditor/ueditor.all.js'
  import '../../../../static/ueditor/lang/zh-cn/zh-cn.js'
  import '../../../../static/ueditor/jquery-2.2.3.min.js'

  export default {
    name: "UEditor",
    props: {
      id: {
          type: String
      },
      config: {
          type: Object,
          zIndex: 0
      }
    },
    data() {
      return {
        editor: null,
      }
    },

    created() {
      this.setUEContent()
      },
    computed: {
      fun: {
        get () { return this.$store.state.user.fun },
        set (val) { this.$store.commit('user/updateFun', val) }
      }
    },
    mounted() {
      //初始化UE
      const _this = this;
      this.editor = UE.delEditor("editor");
      this.editor = UE.getEditor('editor',this.config);
      this.editor = UE.getEditor('editor',
      this.editor.ready(() => {
        this.setUEContent()
        })
      );
    },
    destoryed() {
      this.editor.destory();
    },
    methods:{
      getUEContent: function(){
       return this.editor.getContent();
      },
      getContentTxt: function(){
        return this.editor.getContentTxt();
      },
      setUEContent:function(){
        this.editor.setContent(this.$store.state.user.fun)

      }
    }
  }
</script>
